package com.lemonPiggy.message.receiver;

import cn.hutool.core.util.ObjectUtil;
import com.lemonPiggy.message.redis.listener.JeecgRedisListerer;
import com.lemonPiggy.message.util.BaseMap;
import com.lemonPiggy.message.util.GlobalConstants;
import com.lemonPiggy.message.util.SpringContextUtils;
import lombok.Data;
import org.springframework.stereotype.Component;

/**
 * @author cheng
 * @create 2021-08-27-9:53
 */
@Component
@Data
public class RedisReceiver {


    /**
     * 接受消息并调用业务逻辑处理器
     *
     * @param params
     */
    public void onMessage(BaseMap params) {
        Object handlerName = params.get(GlobalConstants.HANDLER_NAME);
        JeecgRedisListerer messageListener = SpringContextUtils.getHandler(handlerName.toString(), JeecgRedisListerer.class);
        if (ObjectUtil.isNotEmpty(messageListener)) {
            messageListener.onMessage(params);
        }
    }

}
